package com.test.demoweb.web;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

import java.text.SimpleDateFormat;
import java.util.Date;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

@RestController
@RequestMapping("js/a/hello")
public class HelloController {

//    // 返回包含时间字符串的ServerResponse
//    HandlerFunction<ServerResponse> timeFunction = request -> ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).body(
//            Mono.just("Now is" + new SimpleDateFormat("HH:mm:ss").format(new Date())), String.class);
//
//    // 返回包含日期字符串的ServerResponse
//    HandlerFunction<ServerResponse> dateFunction =
//            request -> ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).body(
//                    Mono.just("Today is " + new SimpleDateFormat("yyyy-MM-dd").format(new Date())), String.class);
//
//    RouterFunction<ServerResponse> router = route(GET("/time"), timeFunction)
//            .andRoute(GET("date"), dateFunction);

    @GetMapping("/hello")
    public Mono<String> nihao() {
        return Mono.just("hello,world.");
    }
}
